package com.dy.dept.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: dy
 * @Date: 2022/3/23 - 03 - 23 - 16:47
 * @Description: com.dy.dept.config
 * @version: 1.0
 */
@Component
public class SysConfig implements WebMvcConfigurer {
    @Autowired
    private UserInterceptors userInterceptors;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/html/**")
                .addResourceLocations("classpath:/html/");//classpath:导航到类路径下
        registry.addResourceHandler("/img/**")
                .addResourceLocations("file:f:/img/");//file:导航到本地磁盘下
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOrigins("*");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptors)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/**")
                .excludePathPatterns("/img/**");
    }
}
